import time

class RateLimit:
    def __init__(self, max_calls, period):
        self.max_calls = max_calls
        self.period = period
        self.calls = []

    def __call__(self,func):
        def wrapper(*args,**kwargs):
            now = time.time()
            self.calls = [call_time for call_time in self.calls if now - call_time <self.period]

            if len(self.calls) >=self.max_calls:
                raise Exception(f"调用频率过高，限制为{self.max_calls}次/{self.period}")

            self.calls.append(now)
            return func(*args,**kwargs)
        return wrapper

@RateLimit(3,10)
def api_call():
    print("API调用成功")

for _ in range(4):
    try:
        api_call()
    except Exception as  e:
        print(e)
        break